package com.hbnu.system.controller;

import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.entity.Paper_Qualification;
import com.hbnu.system.service.IPaperQualificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paperqulification")
@Api(tags = "论文量化模块")
public class PaperQualificationController {
    @Autowired
    private IPaperQualificationService iPaperQualificationService;

    @ApiOperation("论文量化添加")
    @PostMapping("/addPaperQualification")
    public Rest<Boolean> addPaperQualification(@RequestBody Paper_Qualification paper_qualification){
        boolean add = iPaperQualificationService.addPaper_Qualification(paper_qualification);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("论文量化删除")
    @GetMapping("/deletePaperQulification")
    public Rest<Boolean> deletePaperQulification(String PaperQualificationID){
        boolean delete = iPaperQualificationService.deletePaper_Qualification(PaperQualificationID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("论文量化查看")
    @GetMapping("/getPaperQulification")
    public Rest<List<Paper_Qualification>> getPaperQulification(String PaperID){
        List<Paper_Qualification> onePaper_qualification = iPaperQualificationService.getOnePaper_Qualification(PaperID);

        return Rest.success(onePaper_qualification);
    }

    @ApiOperation("校级管理员修改量化分数")
    @PostMapping("/upPaperScore")
    public Rest<Boolean> upPaperScore(@RequestBody Paper_Qualification paper_qualification){
        boolean update = iPaperQualificationService.upPaperScore(paper_qualification);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("批量同步量化分数到论文表")
    @PostMapping("/syncAllPaperScores")
    public Rest<Integer> syncAllPaperScores(){
        int count = iPaperQualificationService.syncAllPaperScores();
        return Rest.success(count, "同步成功，共更新 " + count + " 条记录");
    }
}
